# -*- coding=utf8 -*-
from django.template import RequestContext

__author__ = 'nickleo'

from django.core.files.storage import default_storage

from django.views.generic.base import TemplateView
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth import authenticate, login, logout
from django.template.loader import get_template
import jsonpickle as json
import shape_utils


class FakeField(object):
    storage = default_storage


def details(request, b_id):
    name_server = None
    if request.GET.get('name_server') is None:
        name_server = 'Default name_server'
    else:
        name_server = request.GET.get('name_server')

    print name_server + b_id
    return HttpResponse(json.dumps({"msg": name_server + '    bid:'+b_id}))


def charts(request, shape_id):
    name_server = None
    if request.GET.get('name_server') is None:
        name_server = 'Default name_server'
    else:
        name_server = request.GET.get('name_server')
    print json.dumps(shape_utils.shapeCharts())
    return HttpResponse(json.dumps(shape_utils.shapeCharts()))


def all(request):
    list, action_alert = shape_utils.all()
    return HttpResponse(json.encode(list))



def details(request, shape_id):
    print shape_id;
    return HttpResponse(json.dumps({"msg": shape_id}))


def charts(request, shape_id):
    #//"name_server": name_server, "query_time": query_time, "clustername": clustername, "datatype": datatype
    errCode=200
    errDesc=None
    name_server = None
    if request.GET.get('name_server') is None:
        name_server = 'Default name_server'
    else:
        name_server = request.GET.get('name_server')

    query_time = None
    if request.GET.get('query_time') is None:
        errDesc ="query Time is None "
        errCode=400;
    else:
        query_time = request.GET.get('query_time')


    clustername = None
    if request.GET.get('clustername') is None:
        errCode=400
        errDesc='clustername is None'
    else:
        clustername = request.GET.get('clustername')


    if(errCode !=200) :
        resp = HttpResponse()
        resp.status_code=errCode
        resp.reason_phrase=errDesc
        return resp
    else:

        return HttpResponse(json.dumps(shape_utils.shapeCharts(clustername,shape_id,query_time)))
